getApp();

var t = require("../../utils/api"), i = require("../../utils/config"), a = require("../../utils/request"), e = require("../../utils/map-convert");

Page({
    data: {
        themeColor: getApp().globalData.themeColor,
        background: [],
        current: 1,
        indicatorDots: !0,
        vertical: !1,
        autoplay: !0,
        interval: 2e3,
        duration: 500,
        screenWidth: 0,
        screenHeight: 0,
        imgwidth: 0,
        imgheight: 0,
        titleWidth: "80px",
        institutionId: 0,
        institution: {},
        markers: [],
        scale: 18
    },
    onLoad: function(t) {
        this.init(), this.setData({
            institutionId: t.institutionId
        });
    },
    onReady: function() {
        this.selectWcaInstitutionById();
    },
    init: function() {
        var t = this;
        wx.getSystemInfo({
            success: function(i) {
                t.setData({
                    screenHeight: i.windowHeight,
                    screenWidth: i.windowWidth
                });
            }
        });
    },
    imageLoad: function(t) {
        if (0 == this.data.imgwidth || 0 == this.data.imgheight) {
            var i = t.detail.width / t.detail.height, a = this.data.screenWidth, e = a / i;
            this.setData({
                imgwidth: a,
                imgheight: e
            });
        }
    },
    nav: function() {
        wx.openLocation({
            latitude: parseFloat(this.data.institution.wxPointY),
            longitude: parseFloat(this.data.institution.wxPointX),
            name: this.data.institution.name,
            scale: 15,
            address: this.data.institution.address
        });
    },
    makePhone: function() {
        wx.makePhoneCall({
            phoneNumber: this.data.institution.tel
        });
    },
    swiperChange: function(t) {
        this.setData({
            current: t.detail.current + 1
        });
    },
    selectWcaInstitutionById: function() {
        var n = this;
        a.request(a.HttpMethod.GET, t.apiRoute.selectWcaInstitutionById + this.data.institutionId, {}).then(function(t) {
            if ("20000" == t.code) {
                var a = e.bMapToQQMap(t.data.pointX, t.data.pointY);
                t.data.wxPointX = a[0], t.data.wxPointY = a[1], n.setData({
                    institution: t.data,
                    markers: [ {
                        id: "1",
                        latitude: t.data.wxPointY,
                        longitude: t.data.wxPointX,
                        width: 20,
                        height: 20
                    } ]
                });
                var s = [];
                "" != t.data.imageList ? t.data.imageList.forEach(function(t) {
                    s.push(i.institutionImageUrl + t);
                }) : s.push(i.defaultInstitutionImageURL), n.setData({
                    background: s
                });
            } else n.setData({
                institution: void 0
            });
        });
    },
    previewImage: function(t) {
        console.log(t), console.log("show image");
        var i = t.currentTarget.dataset.index, a = this.data.background;
        wx.previewImage({
            current: a[i],
            urls: a
        });
    }
});